<?php
/**
 * Created by PhpStorm.
 * User: 耳火
 * Date: 2018/7/16
 * Time: 15:59
 */

namespace App\Http\Controllers\Api\Hotel;



use App\Facades\Services\StoreLevelService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class StoreLevelController extends Controller
{


    /**
     * 获取所有栏目
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getStoreLevels(Request $request)
    {
        return formatJsonResponse(StoreLevelService::getStoreLevels($request->all()));
    }

    /**
     * 获取栏目详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidateParameterException
     */
    public function getStoreLevel(Request $request)
    {
        $rules = [
            'id' => 'required|exists:store_levels,id'
        ];

        $this->validate($request, $rules);

        return formatJsonResponse(StoreLevelService::getStoreLevels($request->all()));
    }

    /**
     * 创建栏目
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidateParameterException
     */
    public function createStoreLevel(Request $request)
    {

        //验证数据
        $rules = [
            'store_level_name' => 'bail|required|string',
            'parant_id' => 'bail|nullable|integer|exists:store_levels,id',
            'type_id' => 'bail|required'
        ];
        $this->validate($request, $rules);

        StoreLevelService::createStoreLevel($request->all());

        //返回json数据
        return formatJsonResponse();
    }


    /**
     * 更新栏目
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidateParameterException
     */
    public function updateStoreLevel(Request $request)
    {
        $rules = [
            'id' => 'bail|required|integer',
            'store_level_name' => 'bail|filled|string',
            'parant_id' => 'bail|nullable|integer',
            'type_id' => 'bail|filled|integer'
        ];


        $this->validate($request, $rules);

        StoreLevelService::updateStoreLevel($request->all());

        return formatJsonResponse();
    }


    /**
     * 删除栏目
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidateParameterException
     */
    public function deleteStoreLevel(Request $request)
    {
        $rules = [
            'id' => 'required'
        ];

        $this->validate($request,$rules);

        StoreLevelService::deleteStoreLevel($request->all());

        return formatJsonResponse();
    }
}